package sx.login;

import java.awt.CardLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;


public class Gui extends JFrame implements ActionListener{
	private JPanel _0=new JPanel();
	private JPanel _1=new JPanel();
	private JPanel _2=new JPanel();
	private JPanel _3=new JPanel();
	private JTextField loginname=new JTextField("smith",20);
	private JTextField username=new JTextField("xiao",20);
	private JPasswordField password=new JPasswordField("123456",20);
	private JTextField age=new JTextField("24",20);
	private JTextField address=new JTextField("������������",20);
	private JButton register=new JButton("ע   ��");
	private JButton reset=new JButton("��   ��");
	private JButton ret1=new JButton("������һҳ");
	private JButton ret2=new JButton("������һҳ");
	private JButton ret3=new JButton("������һҳ");
	public Gui(){
		super("ע��");
		this.setLocation(300, 300);
		this.setSize(280, 230);
		this.setResizable(false);
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.setVisible(true);
		_0.setLayout(new FlowLayout(FlowLayout.LEFT));
		_1.setLayout(new FlowLayout(FlowLayout.LEFT));
		_2.setLayout(new FlowLayout(FlowLayout.LEFT));
		_3.setLayout(new FlowLayout(FlowLayout.LEFT));
		_0.add(new JLabel("�� ӭ �� �� ע �� ϵ ͳ                                              "));
		_0.add(new JLabel("��¼��"));_0.add(loginname);
		_0.add(new JLabel("�û���"));_0.add(username);
		_0.add(new JLabel("    ����"));_0.add(password);password.setEchoChar('*');
		_0.add(new JLabel("    ����"));_0.add(age);
		_0.add(new JLabel("    ��ַ"));_0.add(address);
		_0.add(register);_0.add(reset);
		_1.add(new JLabel("ע �� �� �� ��                                     "));
		_1.add(new JLabel("�� ӭ �� �� �� �룡                          "));
		_1.add(ret1);
		_2.add(new JLabel("ע �� ʧ �� ��                                     "));
		_2.add(new JLabel("�� �� ¼ �� �� �� �� �� ��             "));
		_2.add(ret2);
		_3.add(new JLabel("ע �� ʧ �� ��                                     "));
		_3.add(new JLabel("�� �� �� �� �� �� �� ��                   "));
		_3.add(ret3);
		this.add(_0);
		register.addActionListener(this);
		reset.addActionListener(this);
		ret1.addActionListener(this);
		ret2.addActionListener(this);
		ret3.addActionListener(this);
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		int flag=1;
		Object src=e.getSource();
		String ln,un,pw,a,addr;
		ln=loginname.getText();un=username.getText();
		pw=password.getText();
		a=age.getText();addr=address.getText();
		if(src==register){
			flag=Register.reg(ln, un, pw, a, addr);
			_0.setVisible(false);
			_1.setVisible(false);
			_2.setVisible(false);
			_3.setVisible(false);
			if(flag==1){this.add(_1);_1.setVisible(true);}
			if(flag==2){this.add(_2);_2.setVisible(true);}
			if(flag==3){this.add(_3);_3.setVisible(true);}
		}else if(src==reset){
			loginname.setText("smith");
			username.setText("xiao");
			password.setText("123456");
			age.setText("24");
			address.setText("������������");
		}else {			
			_0.setVisible(false);
			_1.setVisible(false);
			_2.setVisible(false);
			_3.setVisible(false);
			_0.setVisible(true);
		}
	}

}
